import '../helper/Helper.dart';
import '../helper/dioHelper.dart';

class StationEquip {
  int ID;
  String StationGuid;
  String Name;
  String Model;
  String Remark;
  String EState;
  String FactureTime;
  String FacturerName;

  StationEquip(this.ID, this.StationGuid, this.Name, this.Model, this.Remark,
      this.EState, this.FactureTime, this.FacturerName);
  StationEquip.fromJson(Map<String, dynamic> json)
      : ID = json["ID"],
        StationGuid = json["StationGuid"],
        Name = json["Name"],
        Model = json["Model"],
        Remark = json["Remark"],
        EState = json["EState"],
        FactureTime = json["FactureTime"],
        FacturerName = json["FacturerName"];
  Map<String, dynamic> toJson() => {
        'ID': ID,
        'StationGuid': StationGuid,
        'Name': Name,
        'Model': Model,
        'Remark': Remark,
        'EState': EState,
        'FactureTime': FactureTime,
        'FacturerName': FacturerName,
      };
  static Future<bool> Add(StationEquip x1) async {
    var response = await DioHelper.Post("/StationEquip/Add", x1.toJson());
    if (response.statusCode == 200) return true;
    return false;
  }

  static Future<bool> Update(StationEquip x1) async {
    var response = await DioHelper.Post("/StationEquip/Update", x1.toJson());
    if (response.statusCode == 200) return true;
    return false;
  }

  static Future<bool> Delete(StationEquip x1) async {
    var st = x1.toJson();
    var response = await DioHelper.Post("/StationEquip/Delete", x1.toJson());
    if (response.statusCode == 200) return true;
    return false;
  }

  static Future<StationEquip?> Get(String where, dynamic data) async {
    var response = await DioHelper.Post("/StationEquip/GetByWhere", {
      "Where": where,
      "obj": data,
    });

    if (response.statusCode == 200)
      return new StationEquip.fromJson(response.data);
    return null;
  }

  static Future<List<StationEquip>> GetList(
      String where, dynamic data, int pageIndex, int pageSize) async {
    var response = await DioHelper.Post("/StationEquip/GetListByWhere", {
      "Where": where,
      "obj": data,
      "PageIndex": pageIndex,
      "PageSize": pageSize,
    });
    var list1 = <StationEquip>[];
    if (response.statusCode == 200) {
      for (var x in response.data) {
        list1.add(new StationEquip.fromJson(x));
      }
    }
    return list1;
  }

  static Future<List<StationEquip>> GetAllList() async {
    var response = await DioHelper.Get("/StationEquip/GetAllList", {});
    var list1 = <StationEquip>[];
    if (response.statusCode == 200) {
      for (var x in response.data) {
        list1.add(new StationEquip.fromJson(x));
      }
    }
    return list1;
  }

  static Future<List<String>> GetTypeList() async {
    var response = await DioHelper.Get("/StationEquip/GetEquipType", {});
    var list1 = <String>[];
    if (response.statusCode == 200) {
      print(response.data);
      for (var x in response.data) {
        list1.add(x);
      }
    }
    return list1;
  }
}
